﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using KBVault.DAL.Entities;
using System.Web.UI.HtmlControls;
using KBVault.Web.Infrastructure;

namespace KBVault.Web
{
    public partial class SiteMaster : System.Web.UI.MasterPage
    {
        public string PageTitle { get; set; }
        public string MetaDescription { get; set; }
        public string MetaTags { get; set; }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                htmlCompanyName.InnerText = Settings.Instance.CompanyName;
                htmlTagline.InnerText = Settings.Instance.TagLine;

                if (Session[Constants.SearchQueryKey] != null)
                {
                    txtSearch.Text = Session[Constants.SearchQueryKey].ToString();
                }
            }

            
            var footerContainer = FindControl("htmlFooterContainer") as HtmlGenericControl;
            if (footerContainer == null)
                throw new Exception("No Footer Content Found!");
            footerContainer.Visible = true;
            footerContainer.InnerHtml += "Built by <a href=\"http://en.2bprojevi.com\">KBVault</a> " + DateTime.Now.ToString("yyyy");
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            Session[Constants.SearchQueryKey] = txtSearch.Text;
            Response.Redirect("/Public/Search.aspx");
        }
    }
}
